//
//  SchedulesViewController.m
//  Mecca
//
//  Created by Ryan Enguero on 6/14/14.
//  Copyright (c) 2014 TapDash Heuristics. All rights reserved.
//

#import "SchedulesViewController.h"
#import "SchedulesTableViewCell.h"

#import "ParserClass.h"
#import "Schedules.h"
#import "Artist.h"
#import "Album.h"
#import "UIManager.h"


#define kBgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)

@interface SchedulesViewController ()

@end

@implementation SchedulesViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization

    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self.tblSchedules setBackgroundColor:[UIColor blackColor]];
    
    if ([[[ParserClass sharedItems] schedules] count] == 0) {
        
        UIAlertView *noSched = [[UIAlertView alloc] initWithTitle:@"" message:@"Artist Dont Have A Schedule Yet" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        
        [noSched show];
    }
    
    [self.navigationController.navigationBar setHidden:YES];
    
}


-(void)viewWillAppear:(BOOL)animated{
    
    [self.tabBarController.tabBar setSelectionIndicatorImage:[UIImage imageNamed:@"schedulesTabClicked.png"]];
    
    [self imageLoad:[NSString stringWithFormat:@"http://192.185.93.102/~boomeran/backend-panel/%@",[[ParserClass sharedItems] artistImg]]];
}



-(void)userProfile{
    NSLog(@"User Profile");
    [[UIManager sharedItems]openLeft];
}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    //#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return [[[ParserClass sharedItems] schedules] count];
    //[[[ParserClass sharedItems] songDetails] count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Configure the cell...

    static NSString *cellIdentifier = @"Cell";
    
    SchedulesTableViewCell *cell = (SchedulesTableViewCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    
    if (cell == nil) {
        
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SchedulesTableViewCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
        
    }
    
    Schedules *sched = [[ParserClass sharedItems] schedules][indexPath.row];
    
    cell.eventLbl.text = [sched eventName];
    cell.dateTimeLbl.text = [sched dateTime];
    cell.locationLbl.text = [sched location];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    return cell;
}

- (void)imageLoad:(NSString*)imageStr{

    NSData *imageList = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStr]];
    [UIView animateWithDuration:0.5 animations:^{
        
        self.artistImg.image = [UIImage imageWithData:imageList];
        
    } completion:^(BOOL finished) {
        
    }];
}



#pragma mark - Table view delegate

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
       
}


- (IBAction)backAction:(id)sender {
    
    [self.tabBarController.navigationController popViewControllerAnimated:YES];
    [self dismissViewControllerAnimated:YES completion:nil];
    
}

- (void)viewDidUnload{
    
    [super viewDidUnload];
    
    [[ParserClass sharedItems] emptySchedules];
}

@end
